package com.qqbot.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 业务异常
 * @author 付亚全
 */
public class BusinessException extends Exception {
    private static final Logger logger = LoggerFactory.getLogger(BusinessException.class);
    private static final int DEFAULT_CODE = 0;
    private int code = DEFAULT_CODE;
    private String message;

    /**
     * 构建业务异常
     *
     * @param message 异常信息
     */
    public BusinessException(String message) {
        super(message);
        this.message = message;
    }

    /**
     * 构建业务异常
     *
     * @param code    异常码
     * @param message 异常信息
     */
    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 构建业务异常
     *
     * @param code    异常码
     * @param message 异常信息
     * @param cause   可抛异常
     */
    public BusinessException(int code, String message, Throwable cause) {
        super(message, cause);
        logger.error("Exception happened.", cause);
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
